"""
条件判断
"""

# if
age = 16
if age >= 18:
    print('your age is', age)
    print('adult')
elif age >= 6:
    print('your age is', age)
    print('teenager')
else:
    print('your age is', age)
    print('kid')

# birth = int(input('birth:'))
# if birth < 2000:
#     print('00前')
# else:
#     print('00后')

# match
score = 'A'
match score:
    case 'A':
        print('优秀')
    case 'B':
        print('良好')
    case 'C':
        print('及格')
    case _:
        print('差')

match score:
    case 'A' | 'B':
        print('良好')
    case 'C':
        print('及格')
    case _:
        print('差')

# 匹配列表
args = ['gcc', 'hello.c', 'world.c']
# args = ['clean']
# args = ['gcc']

match args:
    # 如果仅出现gcc，报错:
    case ['gcc']:
        print('gcc: missing source file(s).')
    # 出现gcc，且至少指定了一个文件:第二个字符串绑定到变量file1，后面的任意个字符串绑定到*files
    case ['gcc', file1, *files]:
        print('gcc compile: ' + file1 + ', ' + ', '.join(files))
    # 仅出现clean:
    case ['clean']:
        print('clean')
    case _:
        print('invalid command.')

# 循环
# for
for i in range(1, 10):
    for j in range(1, i + 1):
        print('%d * %d = %d' % (i, j, i * j), end='\t')
    print()

# while
sum = 0
n = 99
while n > 0:
    sum = sum + n
    n = n - 2
print(sum)

# dict
d = {'x': 1, 'y': 2, 'z': 3}
print(d.keys())
print(d['x'])
print(d.get('x1'))

# set
s = {1, 2, 3}
print(s)
d = set([1, 2, 3])
print(d)
d.add(4)
print(d)
